---
title: "Space Between"
# description: "Utilities for controlling the space between child elements."
description: "用于控制子元素之间的间隔的功能类。"
---

import plugin from 'tailwindcss/lib/plugins/space'
import { Variants } from '@/components/Variants'
import { Disabling } from '@/components/Disabling'
import { numbersFirstByPrefix } from '@/utils/sortClasses'

export const classes = {
  plugin,
  sort: numbersFirstByPrefix,
  transformSelector: (selector) => (
    <>
      {selector.split('>').shift().trim().replace(/^\./, '').replace(/\\/g, '')} <span className="ml-1 text-purple-300">> * + *</span>
    </>
  ),
}

<!-- ## Add horizontal space between children -->
## 在子元素之间添加水平间隔

<!-- Control the horizontal space between elements using the `space-x-{amount}` utilities. -->
使用 `space-x-{amount}` 功能类控制元素之间的水平空间。

```html fuchsia
<template preview>
  <div class="flex justify-start">
    <div class="w-16 h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-fuchsia-500">1</div>
    <div class="w-4 h-16 rounded-md bg-fuchsia-300 bg-stripes bg-stripes-white"></div>
    <div class="w-16 h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-fuchsia-500">2</div>
    <div class="w-4 h-16 rounded-md bg-fuchsia-300 bg-stripes bg-stripes-white"></div>
    <div class="w-16 h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-fuchsia-500">3</div>
  </div>
</template>

<div class="flex **space-x-4** ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
```

<!-- ## Add vertical space between children -->
## 在子元素之间添加垂直间隔

<!-- Control the vertical space between elements using the `space-y-{amount}` utilities. -->
使用 `space-y-{amount}` 功能类控制元素之间的垂直空间。

```html lightBlue
<template preview>
  <div>
    <div class="h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-blue-500">1</div>
    <div class="h-6 rounded-md bg-blue-300 bg-stripes bg-stripes-white"></div>
    <div class="h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-blue-500">2</div>
    <div class="h-6 rounded-md bg-blue-300 bg-stripes bg-stripes-white"></div>
    <div class="h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-blue-500">3</div>
  </div>
</template>

<div class="flex **space-y-6** ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
```

<!-- ## Reversing children order -->
## 反转子元素顺序

<!-- If your elements are in reverse order (using say `flex-row-reverse` or `flex-col-reverse`), use the `space-x-reverse` or `space-y-reverse` utilities to ensure the space is added to the correct side of each element. -->
如果您的元素是按相反的顺序排列的(例如使用 `flex-row-reverse` 或 `flex-col-reverse`)，使用 `space-x-reverse` 或 `space-y-reverse` 实用程序来确保空间被添加到每个元素的正确一侧。

```html
<template preview>
  <div class="flex flex-row-reverse justify-start">
    <div class="w-16 h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-fuchsia-500">1</div>
    <div class="w-4 h-16 rounded-md bg-fuchsia-300 bg-stripes bg-stripes-white"></div>
    <div class="w-16 h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-fuchsia-500">2</div>
    <div class="w-4 h-16 rounded-md bg-fuchsia-300 bg-stripes bg-stripes-white"></div>
    <div class="w-16 h-16 text-white text-2xl font-extrabold rounded-md flex items-center justify-center bg-fuchsia-500">3</div>
  </div>
</template>

<div class="flex flex-row-reverse **space-x-4 space-x-reverse** ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
```

---

<!-- ## Responsive -->
## 响应式

<!-- To control the space between elements at a specific breakpoint, add a `{screen}:` prefix to any existing space utility. For example, adding the class `md:space-x-8` to an element would apply the `space-x-8` utility at medium screen sizes and above. -->
要在特定的断点处控制元素之间的空间，可在任何现有的 space 功能类前添加 `{screen}:` 前缀。例如，将 `md:space-x-8` 类添加到元素中，就可以在中等屏幕尺寸及以上的情况下使用 `space-x-8` 功能类。

```html
<div class="flex space-x-2 **md:space-x-8**">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
```

<!-- For more information about Tailwind's responsive design features, check out the [Responsive Design](/docs/responsive-design) documentation. -->
关于 Tailwind 的响应式设计功能的更多信息，请查看 [响应式设计](/docs/responsive-design) 文档。

---

## 定制

<!-- ### Spacing scale -->
### 间隔比例

<!-- If you'd like to customize your values for space between, padding, margin, width, and height all at once, use the `theme.spacing` section of your `tailwind.config.js` file. -->
如果您想一次性自定义 space between、padding、margin、width 和 height 的值，请使用您的 `tailwind.config.js` 文件中的 `theme.spacing` 部分。

```diff-js
  // tailwind.config.js
  module.exports = {
    theme: {
      spacing: {
+       sm: '8px',
+       md: '16px',
+       lg: '24px',
+       xl: '48px',
      }
    }
  }
```

<!-- To customize only the space between values, use the `theme.space` section of your `tailwind.config.js` file. -->
如果只想定制 space between 的值，使用您的 `tailwind.config.js` 文件中的 `theme.space` 部分。

```diff-js
  // tailwind.config.js
  module.exports = {
    theme: {
      space: {
+       sm: '8px',
+       md: '16px',
+       lg: '24px',
+       xl: '48px',
      }
    }
  }
```

<!-- Learn more about customizing the default theme in the [theme customization documentation](/docs/theme#customizing-the-default-theme). -->
在 [主题自定义文档](/docs/theme#customizing-the-default-theme) 中了解更多关于自定义默认主题的信息。

### 变体

<Variants plugin="space" />

### 禁用

<Disabling plugin="space" />
